package com.jingdianjichi.subject.domain.handler.subject;

import com.jingdianjichi.subject.common.enums.IsDeletdFlageEnum;
import com.jingdianjichi.subject.common.enums.SubjectInfoEnum;
import com.jingdianjichi.subject.domain.convert.SubjectJudgeConverter;
import com.jingdianjichi.subject.domain.entity.SubjectAnswerBO;
import com.jingdianjichi.subject.domain.entity.SubjectInfoBO;
import com.jingdianjichi.subject.domain.entity.SubjectOptionBO;
import com.jingdianjichi.subject.infra.basic.entity.SubjectJudge;
import com.jingdianjichi.subject.infra.basic.service.SubjectJudgeService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * SubjectRadioHandler 类
 *
 * @author 熊苏鹏1
 * @date 2025/2/20 21:06
 * @description 单选策略
 */
@Component
public class SubjectJudgeHandler implements SubjectTypeHandler{
    @Resource
    private SubjectJudgeService subjectJudgeService;
    @Override
    public SubjectInfoEnum getSubjectType() {
        return SubjectInfoEnum.JUDGE;
    }

    @Override
    public void add(SubjectInfoBO subjectInfoBO) {
        SubjectJudge subjectJudge = new SubjectJudge();
        SubjectOptionBO subjectOptionBO = subjectInfoBO.getSubjectOptionList().get(0);
        subjectJudge.setSubjectId(subjectInfoBO.getId());
        subjectJudge.setIsDeleted(IsDeletdFlageEnum.NOT_DELETED.getCode());
        subjectJudge.setIsCorrect(subjectOptionBO.getIsCorrect());
        subjectJudgeService.insert(subjectJudge);

    }

    @Override
    public SubjectAnswerBO query( SubjectInfoBO subjectInfoBO) {
        SubjectJudge subjectJudge = new SubjectJudge();
        subjectJudge.setSubjectId(subjectInfoBO.getId());
        List<SubjectJudge> subjectJudge1 = subjectJudgeService.query(subjectJudge);
        List<SubjectOptionBO> subjectOptionBOList = SubjectJudgeConverter.INSTANCE.convertEntityToBoList(subjectJudge1);
        SubjectAnswerBO subjectAnswerBO = new SubjectAnswerBO();
        subjectAnswerBO.setSubjectOptionList(subjectOptionBOList);
        return subjectAnswerBO;
    }
}
